/**
 * 
 */
package lu.med.praxiswahl.wahlumed.client.utilities;

import java.awt.Font;
import java.awt.Frame;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;

import com.toedter.calendar.JDateChooser;
import java.awt.Dimension;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import lu.med.praxiswahl.wahlumed.client.wclient.Main;

/**
 * @author PatrickPierre
 * 
 */
public class DateIntervalChooser extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8310508113032106690L;
	protected JLabel startDateLabel;
	protected JLabel endDateLabel;
	protected JButton okButton;
	protected JButton cancelButton;
	protected JLabel errorLabel;
	protected JDateChooser startTextField;
	protected JDateChooser endTextField;

	protected Main dataManager;
	/**
	 * @param parent
	 * @wbp.parser.constructor
	 */
	public DateIntervalChooser(Frame parent, Main dataManager) {
		super(parent, true);
		this.dataManager = dataManager;
		getContentPane().setBackground(SystemColor.inactiveCaption);
		setBackground(SystemColor.activeCaption);

		startDateLabel = new javax.swing.JLabel();
		startDateLabel.setBounds(10, 43, 75, 20);
		startDateLabel.setFont(new Font("Verdana", Font.PLAIN, 11));
		startDateLabel.setText("Startdatum:");

		endDateLabel = new javax.swing.JLabel();
		endDateLabel.setBounds(235, 43, 62, 20);
		endDateLabel.setFont(new Font("Verdana", Font.PLAIN, 11));
		endDateLabel.setText("Enddatum:");

		startTextField = new JDateChooser();
		startTextField.getDateEditor().setEnabled(true);
		startTextField.setBounds(88, 43, 127, 20);

		endTextField = new JDateChooser();
		endTextField.getDateEditor().setEnabled(true);
		endTextField.setBounds(307, 43, 127, 20);

		okButton = new javax.swing.JButton();
		okButton.setBounds(294, 105, 140, 20);
		okButton.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/login.png")));
		cancelButton = new javax.swing.JButton();
		cancelButton.setBounds(88, 105, 140, 20);
		cancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/cancel.png")));

		errorLabel = new javax.swing.JLabel();
		errorLabel.setFont(new Font("Verdana", Font.PLAIN, 12));
		errorLabel.setBounds(20, 74, 424, 20);
		errorLabel.setForeground(new java.awt.Color(255, 0, 0));

		okButton.setText("Ok");
		okButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				okActionPerformed(evt);
			}
		});

		cancelButton.setText("Abbrechen");
		cancelButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cancelActionPerformed(evt);
			}

		});

		getContentPane().setLayout(null);
		getContentPane().add(startDateLabel);
		getContentPane().add(startTextField);
		getContentPane().add(endDateLabel);
		getContentPane().add(endTextField);
		getContentPane().add(errorLabel);
		getContentPane().add(okButton);
		getContentPane().add(cancelButton);

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setTitle("Auswahl Zeitraum");
		setIconImage(null);
		setName("dateInterval");
		setPreferredSize(new Dimension(500, 200));

	}

	protected void cancelActionPerformed(ActionEvent evt) {
		this.dispose();

	}

	protected void okActionPerformed(ActionEvent evt) {
		// will be in implemented in the derived classes
		//([0-9]{2}).([0-9]{2}).([0-9]{4})
		
	}

	protected Calendar dateToCalendar(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal;
	}
	
	protected String convertDateToString(Date date) {

		DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
		if (date == null) {
			// return df.format(new GregorianCalendar().getTime());
			return null;
		}
		String reportDate = df.format(date);

		return reportDate;
	}
}
